#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include "aux.h"
#include "clsv.h"

#define		FILES_DIR		"files/"

int
fileExists(char * filename)
{
	FILE * aux;
	char auxFile[MAX_FILENAME+10];
	
	sprintf(auxFile, "%s%s", FILES_DIR, filename);
	
	if ((aux = fopen(auxFile, "r")) == NULL)
		return 0;
	
	fclose(aux);
	return 1;
}

void
printTicketParameters(ticketP * tickp)
{
	tickp->id[TICKET_LEN-1] = '\0';
	printf("Ticket ID: %s\n", tickp->id);
	printf("Ticket enabled in: %d seconds\n", tickp->etime - tickp->dtime);
	printf("Ticket expires in: %d seconds\n", tickp->ftime - tickp->dtime);
}

int
getfilesize(const char * path)
{
	struct stat file_status;
	
	if (stat(path, &file_status) != 0)
	{
		;/*Error(ERROR_FILESTATUS);*/
	}
	return file_status.st_size;
}

int
checkFilename(char * filename)
{
	int len = strlen(filename);
	int i;
	char c;
	
	for (i=0; i<len; i++)
	{
		if ((c = filename[i]) < '!' || c > '~')
			return -1;
	}
	
	return 1;
}
